package cn.xuziao.databasecourse.service;

import cn.xuziao.databasecourse.dao.ComplexInfoMap;
import cn.xuziao.databasecourse.dao.SimpleInfoMap;
import cn.xuziao.databasecourse.pojo.ComplexInfo;
import cn.xuziao.databasecourse.pojo.SimpleInfo;
import cn.xuziao.databasecourse.tools.ReManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xuziao
 * @date 2021/11/17 8:55
 */

@Service
public class Search {

    SimpleInfoMap simpleInfoMap;
    OssHandle ossHandle;
    ComplexInfoMap complexInfoMap;

    @Autowired
    public Search(SimpleInfoMap simpleInfoMap, OssHandle ossHandle, ComplexInfoMap complexInfoMap){
        this.simpleInfoMap = simpleInfoMap;
        this.ossHandle = ossHandle;
        this.complexInfoMap = complexInfoMap;
    }

    public List<SimpleInfo> searchImgPath(String info) {
        return simpleInfoMap.selectSimpleInfo("%"+info+"%");
    }

    public SimpleInfo getSimpleRandomInfoObj(String url) {
        return simpleInfoMap.selectSimpleInfoByType("info_path", "'"+url+"'").get(0);
    }

    public ComplexInfo getComplexRandomInfoObj(String url) {
        String name = ReManager.getCNKIImgName(url);
        List<ComplexInfo> complexInfoList =  complexInfoMap.selectComplexInfoByType("name", "'%"+name+"%'");
//        System.out.println(complexInfoList.size());
        if (complexInfoList.size() == 0){
            System.out.println(name);
        }
        return complexInfoList.get(0);
    }

    public List<SimpleInfo> getAllImages(){
        return simpleInfoMap.selectSimpleInfoByType("info_type", "0");
    }

    public List<ComplexInfo> getAllCnkis() {
        return complexInfoMap.selectComplexInfoByType("info_type", "2");
    }


}
